package cn.lili.controller.goods;

import cn.lili.common.utils.ResultUtil;
import cn.lili.common.vo.PageVO;
import cn.lili.common.vo.ResultMessage;
import cn.lili.modules.goods.entity.dos.DutyFreeFAQ;
import cn.lili.modules.goods.service.DutyFreeFAQService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@Api(tags = "免税常见问题")
@RequestMapping("/goods/faq")
@RequiredArgsConstructor
public class DutyFreeFAQController {

    private final DutyFreeFAQService dutyFreeFAQService;

    @ApiOperation(value = "分页获取常见问题")
    @GetMapping
    public ResultMessage<Page<DutyFreeFAQ>> getByPage (DutyFreeFAQ dutyFreeFAQ, PageVO pageVO) {
        return ResultUtil.data(dutyFreeFAQService.getByPage(dutyFreeFAQ, pageVO));
    }

    @ApiOperation(value = "添加")
    @PostMapping
    public ResultMessage<Object> saveFAQ(@RequestBody DutyFreeFAQ dutyFreeFAQ) {
        dutyFreeFAQService.save(dutyFreeFAQ);
        return ResultUtil.success();
    }

    @ApiOperation(value = "修改")
    @PostMapping(value = "/update")
    public ResultMessage<Object> updateFAQ(@RequestBody DutyFreeFAQ dutyFreeFAQ) {
        dutyFreeFAQService.updateById(dutyFreeFAQ);
        return ResultUtil.success();
    }

    @ApiOperation(value = "根据ID获取信息")
    @GetMapping(value = "/{id}")
    public ResultMessage<DutyFreeFAQ> getById(@PathVariable String id) {
        return ResultUtil.data(dutyFreeFAQService.getById(id));
    }

    @ApiOperation(value = "删除")
    @DeleteMapping(value = "/{id}")
    public ResultMessage<String> delete(@PathVariable String id) {
        dutyFreeFAQService.removeById(id);
        return ResultUtil.success();
    }
}
